package com.mspbots.sync.wise.controller;

import com.fasterxml.jackson.databind.JsonNode;
import com.mspbots.sync.wise.service.ScheduleService;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

import java.util.Map;

/**
 * com.mspbots.sync.wise.ScheduleEntryController
 *
 * @author Alex bob(https://github.com/vnobo)
 * @date Created by 2019/10/17
 */
@Log4j2
@RestController
@RequiredArgsConstructor
@RequestMapping(value = "schedules")
public class ScheduleEntryController {

    private final ScheduleService entryService;

    @GetMapping("list")
    public Flux<JsonNode> getList(@RequestParam Map<String, String> params) {
        Assert.notNull(params.get("tenantId"), () -> "Search param tenant id not null.");
        Assert.notNull(params.get("conditions"), () -> "Search param conditions id not null.");
        return this.entryService.getEntriesOnly(params);
    }
}
